home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODMisc / PRODGeom.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.9 KB  |  282 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRODGeom.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef PRODGEOM_H
  13. #include "PRODGeom.h"
  14. #endif
  15.  
  16. #ifndef FWRECT_H
  17. #include "FWRect.h"
  18. #endif
  19.  
  20. #ifndef FWACQUIR_H
  21. #include "FWAcquir.h"
  22. #endif
  23.  
  24. #ifndef FWPRIDEB_H
  25. #include "FWPriDeb.h"
  26. #endif
  27.  
  28. // ----- OpenDoc Includes -----
  29.  
  30. #ifndef SOM_ODShape_xh
  31. #include <Shape.xh>
  32. #endif
  33.  
  34. #ifndef SOM_ODTransform_xh
  35. #include <Trnsform.xh>
  36. #endif
  37.  
  38. #ifndef SOM_ODFrame_xh
  39. #include <Frame.xh>
  40. #endif
  41.  
  42. #ifdef FW_BUILD_MAC
  43. #pragma segment fwodmisc_odgeom
  44. #endif
  45.  
  46. //========================================================================================
  47. // Globals
  48. //========================================================================================
  49.  
  50. // [HLX] We need to release them when the library is unloaded
  51. static ODShape*         FW_gShapeMaker = NULL;
  52. static ODTransform*     FW_gTransformMaker = NULL;
  53.  
  54. //----------------------------------------------------------------------------------------
  55. //    FW_PrivSetShapeTransformMaker
  56. //----------------------------------------------------------------------------------------
  57.  
  58. void SL_API FW_PrivSetShapeTransformMaker(Environment *ev, ODFrame* odFrame)
  59. {
  60.     FW_SOM_TRY
  61.     {
  62.         if (FW_gShapeMaker == NULL)
  63.         {
  64.             FW_gShapeMaker = odFrame->CreateShape(ev);
  65.             
  66.             FW_gShapeMaker->SetRectangle(ev, (ODRect*) &FW_kZeroRect);
  67.         }
  68.             
  69.         if (FW_gTransformMaker == NULL)
  70.             FW_gTransformMaker = odFrame->CreateTransform(ev);
  71.     }
  72.     FW_SOM_CATCH
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_PrivNewODShape_Empty
  77. //----------------------------------------------------------------------------------------
  78.  
  79. ODShape* SL_API FW_PrivNewODShape_Empty(Environment* ev)
  80. {
  81.     //     If you get this assert it means that you are trying to create a shape before your
  82.     //    part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
  83.     //    to create new shapes you cannot create a new shape before having a frame or facet.
  84.     FW_ASSERT(FW_gShapeMaker != NULL);
  85.     
  86.     FW_SOM_TRY
  87.     {
  88.         return FW_gShapeMaker->NewShape(ev);
  89.     }
  90.     FW_SOM_CATCH
  91.     return NULL;
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_PrivNewODShape_PlatformRect
  96. //----------------------------------------------------------------------------------------
  97.  
  98. ODShape* SL_API FW_PrivNewODShape_PlatformRect(Environment *ev, const FW_PlatformRect& rect)
  99. {
  100.     // No try block necessary - Do not throw
  101.     return FW_PrivNewODShape_Rect(ev, FW_CRect(rect));
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    FW_PrivNewODShape_Rect
  106. //----------------------------------------------------------------------------------------
  107.  
  108. ODShape* SL_API FW_PrivNewODShape_Rect(Environment *ev, const FW_SRect& rect)
  109. {
  110.     //     If you get this assert it means that you are trying to create a shape before your
  111.     //    part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
  112.     //    to create new shapes you cannot create a new shape before having a frame or facet.
  113.     FW_ASSERT(FW_gShapeMaker != NULL);
  114.  
  115.     ODShape *odShape  =  NULL;
  116.     FW_VOLATILE(odShape);
  117.     
  118.     FW_TRY
  119.     {
  120.         odShape = FW_gShapeMaker->NewShape(ev);
  121.         odShape->SetRectangle(ev, (ODRect*) &rect);    
  122.     }
  123.     FW_CATCH_BEGIN
  124.     FW_CATCH_EVERYTHING()
  125.     {
  126.         if (odShape!=NULL)
  127.             odShape->Release(ev);
  128.         odShape = NULL;
  129.     }    
  130.     FW_CATCH_END
  131.  
  132.     return odShape;
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_PrivNewODShape_Region
  137. //----------------------------------------------------------------------------------------
  138.  
  139. ODShape* SL_API FW_PrivNewODShape_Region(Environment *ev, ODRgnHandle rgnHandleToAdopt)
  140. {
  141.     //     If you get this assert it means that you are trying to create a shape before your
  142.     //    part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
  143.     //    to create new shapes you cannot create a new shape before having a frame or facet.
  144.     FW_ASSERT(FW_gShapeMaker != NULL);
  145.  
  146.     ODShape *odShape  =  NULL;
  147.     FW_VOLATILE(odShape);
  148.     
  149.     FW_TRY
  150.     {
  151.         odShape = FW_gShapeMaker->NewShape(ev);
  152. #ifdef FW_BUILD_MAC
  153.         odShape->SetQDRegion(ev, rgnHandleToAdopt);
  154. #endif
  155. #ifdef FW_BUILD_WIN
  156.         odShape->SetWinRegion(ev, rgnHandleToAdopt);
  157. #endif
  158.     }
  159.     FW_CATCH_BEGIN
  160.     FW_CATCH_EVERYTHING()
  161.     {    
  162.         if (odShape!=NULL)
  163.             odShape->Release(ev);
  164.         odShape = NULL;
  165.     }
  166.     FW_CATCH_END
  167.     
  168.     return odShape;
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. //    FW_PrivNewODShape_Shape
  173. //----------------------------------------------------------------------------------------
  174.  
  175. ODShape* SL_API FW_PrivNewODShape_Shape(Environment *ev, ODShape* otherShape)
  176. {
  177.     FW_SOM_TRY
  178.     {
  179.         return otherShape->Copy(ev);
  180.     }
  181.     FW_SOM_CATCH
  182.     return NULL;
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_PrivNewODTransform_Empty
  187. //----------------------------------------------------------------------------------------
  188.  
  189. ODTransform* SL_API FW_PrivNewODTransform_Empty(Environment* ev)
  190. {
  191.     //     If you get this assert it means that you are trying to create a transform before your
  192.     //    part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
  193.     //    to create new transforms you cannot create a new transform before having a frame 
  194.     //    or facet.
  195.     FW_ASSERT(FW_gTransformMaker != NULL);
  196.     FW_SOM_TRY
  197.     {
  198.         return FW_gTransformMaker->NewTransform(ev);
  199.     }
  200.     FW_SOM_CATCH
  201.     return NULL;
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. //    FW_PrivNewODTransform_Transform
  206. //----------------------------------------------------------------------------------------
  207.  
  208. ODTransform* SL_API FW_PrivNewODTransform_Transform(Environment *ev, ODTransform* otherTransform)
  209. {
  210.     FW_SOM_TRY
  211.     {
  212.         return otherTransform->Copy(ev);
  213.     }
  214.     FW_SOM_CATCH
  215.     return NULL;
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_PrivNewODTransform_Point
  220. //----------------------------------------------------------------------------------------
  221.  
  222. ODTransform* SL_API FW_PrivNewODTransform_Point(Environment *ev, const FW_SPoint& offset)
  223. {
  224.     //     If you get this assert it means that you are trying to create a transform before your
  225.     //    part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
  226.     //    to create new transforms you cannot create a new transform before having a frame 
  227.     //    or facet.
  228.     FW_ASSERT(FW_gTransformMaker != NULL);
  229.  
  230.     ODTransform *odTransform  =  NULL;
  231.     FW_VOLATILE(odTransform);
  232.     
  233.     FW_TRY
  234.     {
  235.         odTransform = FW_gTransformMaker->NewTransform(ev);
  236.         odTransform->MoveBy(ev, (ODPoint*)&offset);
  237.     }
  238.     FW_CATCH_BEGIN
  239.     FW_CATCH_EVERYTHING()
  240.     {    
  241.         if (odTransform)
  242.             odTransform->Release(ev);
  243.         odTransform = NULL;
  244.     }
  245.     FW_CATCH_END
  246.     
  247.     return odTransform;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_PrivNewODTransform_Point2
  252. //----------------------------------------------------------------------------------------
  253.  
  254. ODTransform* SL_API FW_PrivNewODTransform_Point2(Environment *ev, const FW_SPoint& offset, const FW_SPoint& scale)
  255. {
  256.     //     If you get this assert it means that you are trying to create a transform before your
  257.     //    part got a frame. Because OpenDoc uses factory methods in Frame, Facet and shape
  258.     //    to create new transforms you cannot create a new transform before having a frame 
  259.     //    or facet.
  260.     FW_ASSERT(FW_gTransformMaker != NULL);
  261.  
  262.     ODTransform *odTransform  =  NULL;
  263.     FW_VOLATILE(odTransform);
  264.     
  265.     FW_TRY
  266.     {
  267.         odTransform = FW_gTransformMaker->NewTransform(ev);
  268.         odTransform->ScaleBy(ev, (ODPoint*)&scale);
  269.         odTransform->MoveBy(ev, (ODPoint*)&offset);
  270.     }
  271.     FW_CATCH_BEGIN
  272.     FW_CATCH_EVERYTHING()
  273.     {    
  274.         if (odTransform)
  275.             odTransform->Release(ev);
  276.         odTransform = NULL;
  277.     }
  278.     FW_CATCH_END
  279.     
  280.     return odTransform;
  281. }
  282.